<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>数据看板</span>
        <div>
          <el-button type="default" :class="todayButtonClass" @click="handleTodayButton">今日</el-button>
          <el-button type="default" :class="thisWeekButtonClass" @click="handleThisWeekButton">本周</el-button>
        </div>
      </div>
    </template>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">新客户数量</div>
            <span class="card-panel-num">
<!--              <count-to v-model="newGuest" :time="3000"></count-to>-->
              <vue-count-to :start-val="0" :end-val="newGuest"/>
            </span>
            <!--<count-to :start-val="0" :end-val="102400" :duration="2600" class="card-panel-num" />-->
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-bag">
            <svg-icon icon-class="bag" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">订单数量</div>
            <span class="card-panel-num">
<!--              <count-to v-model="orderNum" :time="3000"></count-to>-->
              <vue-count-to :start-val="0" :end-val="orderNum"/>
            </span>
            <!--<count-to :start-val="0" :end-val="81212" :duration="3000" class="card-panel-num" />-->
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">销售金额（实付）</div>
            <span class="card-panel-num">
<!--              <count-to v-model="salesAmount" :time="3000"></count-to>-->
              <vue-count-to :start-val="0.00" :end-val="salesAmount" :decimals="2"/>
            </span>
            <!--<count-to :start-val="0" :end-val="9280" :duration="3200" class="card-panel-num" />-->
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-completed">
            <svg-icon icon-class="completed" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">完成订单数</div>
            <span class="card-panel-num">
<!--              <count-to v-model="orderComplete" :time="3000"></count-to>-->
              <vue-count-to :start-val="0" :end-val="orderComplete"/>
            </span>
            <!-- <CountTo :start-val="0" :end-val="13600" class="card-panel-num" />-->
          </div>
        </div>
      </el-col>
    </el-row>
  </el-card>
</template>

<script setup>
import {computed, onMounted} from "vue";
import VueCountTo from "@/components/VueCountTo";

const emit = defineEmits(['handleSetLineChartData'])

const newGuest = ref(0);
const orderNum = ref(0);
const salesAmount = ref(0);
const orderComplete = ref(0);
const currentButton = ref("");

const handleSetLineChartData = (type) => {
  emit('handleSetLineChartData', type)
}

function handleTodayButton() {
  currentButton.value = "today";
  const newReportType = "0";
  getPanelData(newReportType);
}

function handleThisWeekButton() {
  currentButton.value = "thisWeek";
  const newReportType = "1";
  getPanelData(newReportType);
}

function getPanelData(newReportType) {
  /*report(newReportType).then(res => {
    const data = res.data;
    salesAmount.value = data.amountPay * 1;
    orderComplete.value = data.finishOrderNum * 1;
    newGuest.value = data.newUserNum * 1;
    orderNum.value = data.orderNum * 1;
  });*/
}

const todayButtonClass = computed(() => {
  return `button${currentButton.value == 'today' ? ' current-button' : ''}`
})
const thisWeekButtonClass = computed(() => {
  return `button${currentButton.value == 'thisWeek' ? ' current-button' : ''}`
})

handleTodayButton();

</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-bag {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-completed {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-bag {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-completed {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.current-button {
  background-color: cornflowerblue;
  color: white;
}
</style>
